//#include "task_devos.h"
//#include "drv.h"
//#include "lib_string.h"
//
//#include "sensor_driver.h"
//#include "algo_math.h"
//
//
////Constant definition
//
////#define GPIO_CHANNEL_EN_ASW		        DRV_GPIO_PIN2
////#define GPIO_CHANNEL_EN_AF			    DRV_GPIO_PIN3
////#define GPIO_CHANNEL_EN_AC			    DRV_GPIO_PIN4
//
//#define ADC_CHANNEL_W1  			    DRV_ADC_CHANNEL0
//#define ADC_CHANNEL_W2	    		    DRV_ADC_CHANNEL1
//#define ADC_CHANNEL_CE	    		    DRV_ADC_CHANNEL2
//
//#define FREQUENCY_DEFAULT             { 10000 }
//#define REFERENCE_SCALE                 1000
//#define REFERENCE_RESISTANCE_DEFAULT	15000
//#define REFERENCE_MAGNITUDE_DEFAULT     122
//#define REFERENCE_ANGLE_DEFAULT         1316    //1.316r
//#define REFERENCE_COSINE_DEFAULT        252     //cos(1.316r)
//#define REFERENCE_SINE_DEFAULT          968     //sin
//#define REFERENCE_ANGLE_CORRECTION
//#define REFERENCE_ANGLE_ERROR         ( 75 * REFERENCE_ANGLE_DEFAULT / REFERENCE_SCALE )
//
//#define COMMAND_CODE_BLOCK_WRITE        0xA0
//#define COMMAND_CODE_BLOCK_READ         0xA1
//#define COMMAND_CODE_ADDRESS_POINTER    0xB0
//
//#define COMMAND_DATA_SIZE               6
//#define SLAVE_ADDRESS   				0x0D
//
//#define SYSTEM_CLOCK					16000000
//#define START_FREQUENCY					10000
//#define FREQUENCY_INCREMENT				0
//#define INCREMENTS_NUMBER				0
//#define SETTLING_TIME_CYCLES			15
//
//#define RETRY_TIMES                     3
//
//#define CONTROL_GPA                     0x0000 //On:0x0000, Off:0x0100
//#define CONTROL_VOLTAGE                 0x0200 //Mode1:0x0000, Mode2:0x0600, Mode3:0x0400, Mode4:0x0200
//#define CONTROL_INITIALIZE			  (	0x1000 | CONTROL_VOLTAGE | CONTROL_GPA )
//#define CONTROL_START_FREQUENCY		  ( 0x2000 | CONTROL_VOLTAGE | CONTROL_GPA )
//#define CONTROL_INCREMENT_FREQUENCY	  (	0x3000 | CONTROL_VOLTAGE | CONTROL_GPA )
//#define CONTROL_REPEAT_FREQUENCY	  (	0x4000 | CONTROL_VOLTAGE | CONTROL_GPA )
//#define CONTROL_POWER_DOWN_MODE		  (	0xA000 | CONTROL_VOLTAGE | CONTROL_GPA )
//#define CONTROL_STANDBY_MODE		  (	0xB000 | CONTROL_VOLTAGE | CONTROL_GPA )
//
//#define STATUS_VALID_DATA				(1 << 1)
//#define STATUS_SWEEP_COMPLETE			(1 << 2)
//
//#define FREQUENCY_CODE(frequency)		( ( ( (uint64)(frequency) << 27 ) * 16) / SYSTEM_CLOCK )
//
//
////Type definition
//
//typedef enum
//{
//    SENSOR_COUNT_FLAG
//} sensor_flag;
//
//typedef enum
//{
//    SENSOR_OPERATION_WRITE = 0,
//    SENSOR_OPERATION_READ,
//    SENSOR_COUNT_OPERATION
//} sensor_operation;
//
//typedef enum
//{
//    SENSOR_REGISTER_CONTROL = 0,
//    SENSOR_REGISTER_START_FREQUENCY,
//    SENSOR_REGISTER_FREQUENCY_INCREMENT,
//    SENSOR_REGISTER_INCREMENTS_NUMBER,
//    SENSOR_REGISTER_SETTLING_TIME_CYCLES,
//    SENSOR_REGISTER_STATUS,
//    SENSOR_REGISTER_REAL_DATA,
//    SENSOR_REGISTER_IMAGINARY_DATA,
//    SENSOR_COUNT_REGISTER
//} sensor_register;
//
//typedef struct
//{
//    uint8 u8_Code;
//    uint8 u8_Parameter;
//    uint8 u8_Data[COMMAND_DATA_SIZE];
//} sensor_command;
//
//
////Private variable definition
//
//static const uint32 m_u32_FreqDefault[FREQUENCY_COUNT] = FREQUENCY_DEFAULT;
//
//static uint m_ui_FreqCount = FREQUENCY_COUNT;
//static sint16 m_s16_RealRaw[FREQUENCY_COUNT] = {0};
//static sint16 m_s16_ImagRaw[FREQUENCY_COUNT] = {0};
//static sint16 m_s16_Real[FREQUENCY_COUNT] = {0};
//static sint16 m_s16_Imag[FREQUENCY_COUNT] = {0};
//
//static uint m_ui_ImpCalibrated = FUNCTION_OK;
//static sensor_reference m_t_Reference =
//{
//    {0},
//    REFERENCE_RESISTANCE_DEFAULT,
//    FREQUENCY_DEFAULT,
//    { REFERENCE_RESISTANCE_DEFAULT * REFERENCE_MAGNITUDE_DEFAULT },
//    { REFERENCE_COSINE_DEFAULT },
//    { REFERENCE_SINE_DEFAULT }
//};
//
//static const uint8 m_u8_RegisterCode[SENSOR_COUNT_REGISTER] =
//{
//    0x80, 0x82, 0x85, 0x88, 0x8A, 0x8F, 0x94, 0x96
//};
//static const uint m_ui_RegisterByteCount[SENSOR_COUNT_REGISTER] =
//{
//    2, 3, 3, 2, 2, 1, 2, 2
//};
//
////Private function declaration
//static uint SenDrv_LoadImpCalibration(void);
//static sint32 GetMilliVolt( uint ui_Channel );
//static int32 ReadIWorking( uint ui_Channel );
//static void CorrectImpedance(void);
//
//static uint TransferRegister(uint ui_Register,
//                             uint ui_Operation,
//                             uint8 *u8p_Data );
//
//static void ReverseData( const uint8 *u8p_Source,
//                         uint8 *u8p_Target,
//                         uint ui_Length );
//
//static uint TryTransfer( uint (*f)(uint, uint, uint8*),
//                         uint ui_Register,
//                         uint ui_Operation,
//                         uint8 *u8p_Data);
//
//
//// Function definition
//
//uint SenDrv_Initialize(void)
//{
//    uint ui_Value;
//
//    ui_Value = DRV_GPIO_MODE_OUTPUT;
////    DrvGPIO_SetConfig( GPIO_CHANNEL_EN_ASW, DRV_GPIO_PARAM_MODE,
////                       (const uint8 *)&ui_Value, sizeof(ui_Value) );
////    DrvGPIO_SetConfig( GPIO_CHANNEL_EN_AF, DRV_GPIO_PARAM_MODE,
////                       (const uint8 *)&ui_Value, sizeof(ui_Value) );
////    DrvGPIO_SetConfig( GPIO_CHANNEL_EN_AC, DRV_GPIO_PARAM_MODE,
//////                       (const uint8 *)&ui_Value, sizeof(ui_Value) );
////    DrvGPIO_Set( GPIO_CHANNEL_EN_ASW );
////    DrvGPIO_Set( GPIO_CHANNEL_EN_AF );
//////    DrvGPIO_Set( GPIO_CHANNEL_EN_AC );
////    DrvGPIO_Clear( GPIO_CHANNEL_EN_AC );
//
//    SenDrv_LoadImpCalibration();
//
//    return FUNCTION_OK;
//}
//
//
//uint SenDrv_SetConfig( uint ui_Parameter,
//                       const uint8 *u8p_Value,
//                       uint ui_Length )
//{
//    switch ( ui_Parameter ){
//    case SENDRV_PARAM_REFERENCE:
//        if (ui_Length == sizeof(m_t_Reference.s32_Risistance))
//        {
//            m_t_Reference.s32_Risistance = *((const sint32 *)u8p_Value);
//            m_ui_ImpCalibrated = FUNCTION_FAIL;
//            break;
//        }
//        else if (ui_Length == sizeof(uint8 ))
//        {
//            SenDrv_ShiftCalibration();
//            return SenDrv_SaveImpCalibration();
//        }
//        else if (ui_Length == sizeof(m_t_Reference))
//        {
//            Lib_Memcpy( (uint8 *)&m_t_Reference, u8p_Value, ui_Length );
//            return SenDrv_SaveImpCalibration();
//        }
//        else
//        {
//            return FUNCTION_FAIL;
//        }
//    default:
//        return FUNCTION_FAIL;
//    }
//
//    return FUNCTION_OK;
//}
//
//
//uint SenDrv_GetConfig( uint ui_Parameter,
//                       uint8 *u8p_Value,
//                       uint *uip_Length )
//{
//    switch ( ui_Parameter ){
//    case SENDRV_PARAM_STATE:
//        break;
//
//    case SENDRV_PARAM_REFERENCE:
//        Lib_Memcpy( u8p_Value, (const uint8 *)&m_t_Reference, sizeof(m_t_Reference) );
//        break;
//
//    default:
//        return FUNCTION_FAIL;
//    }
//
//	return FUNCTION_OK;
//}
//
//int32 SenDrv_ReadVCounter(void)
//{
////    int32 i32_Value;
////
////    i32_Value = GetMilliVolt(ADC_CHANNEL_CE) / 10;
////    return i32_Value;
//    return 0;
//}
//
//int32 SenDrv_ReadISignal(void)
//{
////    return ReadIWorking(ADC_CHANNEL_W1) - m_t_Reference.s32_Shift[SENDRV_CHANNEL_W1];
//    return 0;
//}
//
//int32 SenDrv_ReadIBackground(void)
//{
////    return ReadIWorking(ADC_CHANNEL_W2) - m_t_Reference.s32_Shift[SENDRV_CHANNEL_W2];
//    return 0;
//}
//
//static int32 ReadIWorking( uint ui_Channel )
//{
////    int32 i32_Value;
////
////    i32_Value = GetMilliVolt(ui_Channel);
////    i32_Value = (i32_Value - 2048) * 20;
////
////    return i32_Value;
//    return 0;
//}
//
//static sint32 GetMilliVolt( uint ui_Channel )
//{
////    uint16 u16_Value;
////    DrvADC_Read(ui_Channel, &u16_Value);
////    return (sint32)u16_Value;
//    return 0;
//}
//
//void SenDrv_ShiftCalibration(void)
//{
//#define SHIFT_CAL_COUNT     50
//    sint32 i32_Value;
//    uint i;
//
//    i32_Value = 0;
//    for (i=0; i<SHIFT_CAL_COUNT; i++)
//        i32_Value += 0;//ReadIWorking(ADC_CHANNEL_W1);
//    i32_Value /= SHIFT_CAL_COUNT;
//    m_t_Reference.s32_Shift[SENDRV_CHANNEL_W1] = i32_Value;
//
//    i32_Value = 0;
//    for (i=0; i<SHIFT_CAL_COUNT; i++)
//        i32_Value += 0;//ReadIWorking(ADC_CHANNEL_W2);
//    i32_Value /= SHIFT_CAL_COUNT;
//    m_t_Reference.s32_Shift[SENDRV_CHANNEL_W2] = i32_Value;
//}
//
//
//uint SenDrv_EnableImpedance()
//{
//    uint ui_Value = 1;
//    if ( DrvI2C_SetConfig( DRV_I2C_DEVICE_ID_1,
//                           DRV_I2C_PARAM_SWITCH,
//                           (const uint8 *)&ui_Value,
//                           sizeof(ui_Value) ) != FUNCTION_OK)
//        return FUNCTION_FAIL;
//
////    DrvGPIO_Set( GPIO_CHANNEL_EN_AC );
//////    DrvGPIO_Clear( GPIO_CHANNEL_EN_AF );
//
//    return FUNCTION_OK;
//}
//
//static uint TryTransfer( uint (*f)(uint, uint, uint8*),
//                         uint ui_Register,
//                         uint ui_Operation,
//                         uint8 *u8p_Data)
//{
//    uint i;
//
//    for (i=0; i<RETRY_TIMES; i++)
//    {
//        if ( f(ui_Register, ui_Operation, u8p_Data) == FUNCTION_OK )
//            break;
//    }
//
//    if (i<RETRY_TIMES)
//    {
//        return FUNCTION_OK;
//    }
//    else
//    {
//        m_ui_FreqCount = (m_ui_FreqCount+FREQUENCY_COUNT-1) % FREQUENCY_COUNT;
//        return FUNCTION_FAIL;
//    }
//}
//
//uint SenDrv_SetupImpedance()
//{
//    uint32 u32_Value;
//
//    m_ui_FreqCount = (m_ui_FreqCount+1) % FREQUENCY_COUNT;
//
//    u32_Value = FREQUENCY_CODE(m_t_Reference.s32_Freq[m_ui_FreqCount]);
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_START_FREQUENCY,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = FREQUENCY_CODE(FREQUENCY_INCREMENT);
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_FREQUENCY_INCREMENT,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = INCREMENTS_NUMBER;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_INCREMENTS_NUMBER,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = SETTLING_TIME_CYCLES;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_SETTLING_TIME_CYCLES,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = CONTROL_STANDBY_MODE;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_CONTROL,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = CONTROL_INITIALIZE;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_CONTROL,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    return FUNCTION_OK;
//}
//
//uint SenDrv_DisableImpedance(void)
//{
//    uint ui_Value = 0;
//
////    DrvGPIO_Clear( GPIO_CHANNEL_EN_AC );
//////    DrvGPIO_Set( GPIO_CHANNEL_EN_AF );
//
//    DrvI2C_SetConfig( DRV_I2C_DEVICE_ID_1,
//                      DRV_I2C_PARAM_SWITCH,
//                      (const uint8 *)&ui_Value,
//                      sizeof(ui_Value) );
//
//    return FUNCTION_OK;
//}
//
//uint SenDrv_UnblockImpedance(void)
//{
//    uint ui_Value = 0;
//    DrvI2C_SetConfig( DRV_I2C_DEVICE_ID_1,
//                      DRV_I2C_PARAM_SWITCH,
//                      (const uint8 *)&ui_Value,
//                      sizeof(ui_Value) );
//    DrvI2C_SetConfig( DRV_I2C_DEVICE_ID_1,
//                      DRV_I2C_PARAM_BUSY,
//                      (const uint8 *)&ui_Value,
//                      sizeof(ui_Value) );
//
//    return FUNCTION_OK;
//}
//
//uint SenDrv_GetImpedance(void)
//{
//    uint32 u32_Value;
//
//    u32_Value = CONTROL_START_FREQUENCY;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_CONTROL,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = 0;
//    while (((uint8)u32_Value & STATUS_VALID_DATA) == 0)
//    {
//        if ( TryTransfer(TransferRegister,
//                         SENSOR_REGISTER_STATUS,
//                         SENSOR_OPERATION_READ,
//                         (uint8 *)&u32_Value) != FUNCTION_OK )
//            return FUNCTION_FAIL;
//    }
//
//    while (((uint8)u32_Value & STATUS_SWEEP_COMPLETE) == 0)
//    {
//        u32_Value = CONTROL_INCREMENT_FREQUENCY;
//        if ( TryTransfer(TransferRegister,
//                         SENSOR_REGISTER_CONTROL,
//                         SENSOR_OPERATION_WRITE,
//                         (uint8 *)&u32_Value) != FUNCTION_OK )
//            return FUNCTION_FAIL;
//
//        u32_Value = 0;
//        if ( TryTransfer(TransferRegister,
//                         SENSOR_REGISTER_STATUS,
//                         SENSOR_OPERATION_READ,
//                         (uint8 *)&u32_Value) != FUNCTION_OK )
//            return FUNCTION_FAIL;
//    }
//
//
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_REAL_DATA,
//                     SENSOR_OPERATION_READ,
//                     (uint8 *)&m_s16_RealRaw[m_ui_FreqCount]) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_IMAGINARY_DATA,
//                     SENSOR_OPERATION_READ,
//                     (uint8 *)&m_s16_ImagRaw[m_ui_FreqCount]) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    u32_Value = CONTROL_POWER_DOWN_MODE;
//    if ( TryTransfer(TransferRegister,
//                     SENSOR_REGISTER_CONTROL,
//                     SENSOR_OPERATION_WRITE,
//                     (uint8 *)&u32_Value) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    return FUNCTION_OK;
//}
//
//uint SenDrv_ReadImpedance( sint8 s8_FreqCount,
//                           sint16 *s16p_Real,
//                           sint16 *s16p_Imag,
//                           sint16 *s16p_RealRaw,
//                           sint16 *s16p_ImagRaw,
//                           uint8 *u8p_Freq )
//{
//    if (s8_FreqCount < 0 || s8_FreqCount >= FREQUENCY_COUNT)
//    {
//        s8_FreqCount = m_ui_FreqCount;
//        CorrectImpedance();
//    }
//
//    *s16p_Real = m_s16_Real[s8_FreqCount];
//    *s16p_Imag = m_s16_Imag[s8_FreqCount];
//    *s16p_RealRaw = m_s16_RealRaw[s8_FreqCount];
//    *s16p_ImagRaw = m_s16_ImagRaw[s8_FreqCount];
//    *u8p_Freq = (uint8)(m_t_Reference.s32_Freq[s8_FreqCount]/1000);
//
//    if ( s8_FreqCount+1 >= FREQUENCY_COUNT )
//        return FUNCTION_OK;
//    else
//        return FUNCTION_FAIL;
//}
//
//void CorrectImpedance(void)
//{
//    sint32 s32_Temp1, s32_Temp2, s32_RealTemp, s32_ImagTemp, s32_Real, s32_Imag;
//
//    s32_Real = 0x7FFF;
//    s32_Imag = 0;
//    s32_RealTemp = (sint32)m_s16_RealRaw[m_ui_FreqCount];
//    s32_ImagTemp = (sint32)m_s16_ImagRaw[m_ui_FreqCount];
//    s32_Temp1 = s32_RealTemp*s32_RealTemp + s32_ImagTemp*s32_ImagTemp;
//
//    if (s32_Temp1>255)
//    {
//        s32_Temp2 = ABS(s32_RealTemp);
//        s32_Temp2 = s32_Temp2<1000? 1 : ( s32_Temp2<10000? 10 : 100 );
//        s32_RealTemp = s32_RealTemp * (m_t_Reference.s32_Factor[m_ui_FreqCount]/s32_Temp2) / (s32_Temp1/s32_Temp2);
//
//        s32_Temp2 = ABS(s32_ImagTemp);
//        s32_Temp2 = s32_Temp2<1000? 1 : ( s32_Temp2<10000? 10 : 100 );
//        s32_ImagTemp = s32_ImagTemp * (m_t_Reference.s32_Factor[m_ui_FreqCount]/s32_Temp2) / (s32_Temp1/s32_Temp2);
//
//        s32_Real = (s32_RealTemp*m_t_Reference.s32_Cosine[m_ui_FreqCount] - s32_ImagTemp*m_t_Reference.s32_Sine[m_ui_FreqCount]) / REFERENCE_SCALE;
//        s32_Imag = (s32_RealTemp*m_t_Reference.s32_Sine[m_ui_FreqCount] + s32_ImagTemp*m_t_Reference.s32_Cosine[m_ui_FreqCount]) / REFERENCE_SCALE;
//
//#ifdef REFERENCE_ANGLE_CORRECTION
//        s32_RealTemp = s32_Real;
//        s32_ImagTemp = s32_Imag;
//        s32_Temp1 = REFERENCE_ANGLE_ERROR
//                * m_t_Reference.s32_Factor[m_ui_FreqCount]
//                / Sqrt(s32_Temp1)
//                * REFERENCE_SCALE
//                / m_t_Reference.s32_Risistance
//                / REFERENCE_SCALE
//                - REFERENCE_ANGLE_ERROR;
//        s32_Temp2 = Sqrt( REFERENCE_SCALE*REFERENCE_SCALE - s32_Temp1*s32_Temp1 );
//        s32_Real = (s32_RealTemp*s32_Temp2 - s32_ImagTemp*s32_Temp1) / REFERENCE_SCALE;
//        s32_Imag = (s32_RealTemp*s32_Temp1 + s32_ImagTemp*s32_Temp2) / REFERENCE_SCALE;
//#endif
//
//        if (s32_Real<-0x8000 || s32_Real>0x7FFF || s32_Imag<-0x8000 || s32_Imag>0x7FFF)
//        {
//            s32_Real = 0x7FFF;
//            s32_Imag = 0;
//        }
//    }
//
//    m_s16_Real[m_ui_FreqCount] = (sint16)s32_Real;
//    m_s16_Imag[m_ui_FreqCount] = (sint16)s32_Imag;
//}
//
//uint SenDrv_CheckImpCalibrated(void)
//{
//    return m_ui_ImpCalibrated;
//}
//
//uint SenDrv_ImpedanceCalibration(void)
//{
//     sint32 s32_scale = 100;
//     sint32 s32_Magnitude, s32_Real, s32_Imag;
//
//     s32_Real = (sint32)m_s16_RealRaw[m_ui_FreqCount] * s32_scale;
//     s32_Imag = (sint32)m_s16_ImagRaw[m_ui_FreqCount] * s32_scale;
//     s32_Magnitude = Sqrt(s32_Real*s32_Real + s32_Imag*s32_Imag);
//
//     if (s32_Magnitude>0)
//     {
//         s32_Real *= REFERENCE_SCALE;
//         s32_Imag *= REFERENCE_SCALE;
//         m_t_Reference.s32_Factor[m_ui_FreqCount] = S_DIV( m_t_Reference.s32_Risistance * s32_Magnitude, s32_scale );
//         m_t_Reference.s32_Cosine[m_ui_FreqCount] = S_DIV( s32_Real, s32_Magnitude );
//         m_t_Reference.s32_Sine[m_ui_FreqCount] = - S_DIV( s32_Imag, s32_Magnitude );
//     }
//
//     if ( m_ui_FreqCount+1 >= FREQUENCY_COUNT )
//         m_ui_ImpCalibrated = FUNCTION_OK;
//
//     return m_ui_ImpCalibrated;
//}
//
//uint SenDrv_SaveImpCalibration(void)
// {
//     uint ui_Return;
//
//     if ( TaskDevOS_OpenFile() != FUNCTION_OK )
//         return FUNCTION_FAIL;
//     ui_Return = TaskDevOS_SaveFileWithCheck( TASK_DEVOS_FILE_ID_REFERENCE,
//                                              (const uint8 *)&m_t_Reference,
//                                              sizeof(m_t_Reference) );
//     TaskDevOS_CloseFile();
//
//     return ui_Return;
// }
//
//static uint SenDrv_LoadImpCalibration(void)
// {
//     uint ui_Return;
//
//     if ( TaskDevOS_OpenFile() != FUNCTION_OK )
//         return FUNCTION_FAIL;
//     ui_Return = TaskDevOS_LoadFileWithCheck( TASK_DEVOS_FILE_ID_REFERENCE,
//                                              (uint8 *)&m_t_Reference,
//                                              sizeof(m_t_Reference) );
//     if ( ui_Return != FUNCTION_OK || m_t_Reference.s32_Factor[0] <= 0 )
//     {
//         uint i;
//         for (i=0; i<SENDRV_COUNT_CHANNELS; i++)
//         {
//             m_t_Reference.s32_Shift[i] = 0;
//         }
//         m_t_Reference.s32_Risistance = REFERENCE_RESISTANCE_DEFAULT;
//         for (i=0; i<FREQUENCY_COUNT; i++)
//         {
//             m_t_Reference.s32_Freq[i] = m_u32_FreqDefault[i];
//             m_t_Reference.s32_Factor[i] = REFERENCE_RESISTANCE_DEFAULT * REFERENCE_MAGNITUDE_DEFAULT;
//             m_t_Reference.s32_Cosine[i] = REFERENCE_COSINE_DEFAULT;
//             m_t_Reference.s32_Sine[i] = REFERENCE_SINE_DEFAULT;
//         }
//         TaskDevOS_SaveFileWithCheck( TASK_DEVOS_FILE_ID_REFERENCE,
//                                      (const uint8 *)&m_t_Reference,
//                                      sizeof(m_t_Reference) );
//     }
//     TaskDevOS_CloseFile();
//
//     return ui_Return;
// }
//
//static uint TransferRegister( uint ui_Register,
//                               uint ui_Operation,
//                               uint8 *u8p_Data )
//{
//    uint ui_Length;
//    sensor_command t_Command;
//
//    if (ui_Register >= SENSOR_COUNT_REGISTER)
//        return FUNCTION_FAIL;
//
//    ui_Length = m_ui_RegisterByteCount[ui_Register];
//
//    t_Command.u8_Code = COMMAND_CODE_ADDRESS_POINTER;
//    t_Command.u8_Parameter = m_u8_RegisterCode[ui_Register];
//    if ( DrvI2C_Transfer( DRV_I2C_DEVICE_ID_1,
//                          SLAVE_ADDRESS,
//                          (const uint8 *)&t_Command,
//                          (uint8 *)0,
//                          sizeof(t_Command) - sizeof(t_Command.u8_Data),
//                          0 ) != FUNCTION_OK )
//        return FUNCTION_FAIL;
//
//    t_Command.u8_Parameter = (uint8)ui_Length;
//    if (ui_Operation == SENSOR_OPERATION_WRITE)
//    {
//        t_Command.u8_Code = COMMAND_CODE_BLOCK_WRITE;
//        ReverseData(u8p_Data, t_Command.u8_Data, ui_Length);
//        if (DrvI2C_Transfer( DRV_I2C_DEVICE_ID_1,
//                             SLAVE_ADDRESS,
//                             (uint8 *)&t_Command,
//                             (uint8 *)0,
//                             sizeof(t_Command) - sizeof(t_Command.u8_Data) + ui_Length,
//                             0 ) != FUNCTION_OK )
//            return FUNCTION_FAIL;
//    }
//    else
//    {
//        t_Command.u8_Code = COMMAND_CODE_BLOCK_READ;
//        if (DrvI2C_Transfer( DRV_I2C_DEVICE_ID_1,
//                             SLAVE_ADDRESS,
//                             (uint8 *)&t_Command,
//                             t_Command.u8_Data,
//                             sizeof(t_Command) - sizeof(t_Command.u8_Data),
//                             ui_Length) != FUNCTION_OK )
//            return FUNCTION_FAIL;
//        ReverseData(t_Command.u8_Data, u8p_Data, ui_Length);
//    }
//
//    return FUNCTION_OK;
//}
//
//static void ReverseData( const uint8 *u8p_Source,
//                         uint8 *u8p_Target,
//                         uint ui_Length )
//{
//    for (uint i = 0; i < ui_Length; i++)
//        u8p_Target[i] = u8p_Source[ui_Length - i - 1];
//}
